<html>
<head><meta charset="utf-8"><title>finding impl&#x27;s for better suggestions · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html">finding impl&#x27;s for better suggestions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195745991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/finding%20impl%27s%20for%20better%20suggestions/near/195745991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Samrat Man Singh <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html#195745991">(Apr 29 2020 at 17:46)</a>:</h4>
<p>Hi, I'm working on issue <a href="https://github.com/rust-lang/rust/issues/71580" title="https://github.com/rust-lang/rust/issues/71580">#71580</a> to suggest <code>into()</code> instead of <code>try_into()</code> if possible. In the thread there Jonas suggested looking for the impl(eg. <code>impl Into&lt;isize&gt; from i16</code>) as a way to have a more robust mechanism to do this.</p>
<p>I'm a bit stumped on how I can go about finding the impl. From Jonas's comment it seems I can achieve this by using <code>rustc_trait_selection::traits::SelectionContext::select</code>, however I'm not entirely sure how I can construct an <code>Obligation</code> to pass.</p>
<p>I'd appreaciate any advice on how I can proceed with SelectionContext, or alternative ways</p>



<a name="195932314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/finding%20impl%27s%20for%20better%20suggestions/near/195932314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html#195932314">(May 01 2020 at 04:58)</a>:</h4>
<p><span class="user-mention" data-user-id="247305">@Samrat Man Singh</span> that is <em>the</em> (only) way, and the obligation is just a predicate (which will be your <code>X: Into&lt;Y&gt;</code>) and a "cause" - if you're not going to report an error from this lookup (which diagnostics wouldn't), you can use a dummy cause</p>



<a name="195932421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/finding%20impl%27s%20for%20better%20suggestions/near/195932421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html#195932421">(May 01 2020 at 05:01)</a>:</h4>
<p><span class="user-mention" data-user-id="247305">@Samrat Man Singh</span> there's also the <code>predicate_for_trait_def</code> helper function but idk how often it's used</p>



<a name="195932430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/finding%20impl%27s%20for%20better%20suggestions/near/195932430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html#195932430">(May 01 2020 at 05:01)</a>:</h4>
<p>/me is looking at <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/coercion.rs#L543-L551" title="https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/coercion.rs#L543-L551">https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/check/coercion.rs#L543-L551</a></p>



<a name="195936167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/finding%20impl%27s%20for%20better%20suggestions/near/195936167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil H <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html#195936167">(May 01 2020 at 06:41)</a>:</h4>
<p>In Clippy we have a small helper using <code>predicate_for_trait_def</code>: <a href="https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/mod.rs#L323" title="https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/mod.rs#L323">https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/mod.rs#L323</a></p>



<a name="195936218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/finding%20impl%27s%20for%20better%20suggestions/near/195936218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil H <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/finding.20impl&#x27;s.20for.20better.20suggestions.html#195936218">(May 01 2020 at 06:42)</a>:</h4>
<p>ah this is about finding impls, not traits</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>